function zoomBox() {
	this.index.apply(this, arguments)
}

zoomBox.prototype = {
	index : function(win, zoom) {
		var win = document.getElementById(win);
		var box = document.getElementById(zoom);
		var img = box.getElementsByTagName('IMG')[0];
		var zoom = img.width / win.getElementsByTagName('IMG')[0].width;
		var z = Math.round(box.offsetWidth / 2);
		win.onmousemove = function(e) {
			e = e || window.event;
			var x = e.clientX, y = e.clientY, ori = win.getBoundingClientRect();
			if (x > ori.right + 20 || y > ori.bottom + 20 || x < ori.left - 20
					|| y < ori.top - 20)
				box.style.display = 'none';
			x -= ori.left;
			y -= ori.top;
			box.style.left = x - z + 'px';
			box.style.top = y - z + 'px';
			img.style.left = -x * zoom + z + 'px';
			img.style.top = -y * zoom + z + 'px';
		}
		win.onmouseover = function() {
			box.style.display = ''
		}
	}
};
window.onload = function() {
	x = new zoomBox('zoomPan', 'zoom')
}

function youLove(typeId){
	$("#cxs_content").html('<li style="text-align: center;"><img alt="这种加载" src="/image/front/loading.gif"></li>');
	$.ajax({
	   type: "POST",
	   url: "/forward/view/book_youLove.go",
	   data: "maxrecord=8&page=1&typeId="+typeId,
	   success: function(html){
	     $("#cxs_content").html(html);
	   }
	});
}
/**
 * div 回调显示区域
 * form 提交的Form表单
 * */
function ajaxFormSubmit(div,form){
	 $(form).ajaxSubmit(function(responseText) { 
         $(div).html(responseText);
     }); 
}
/**
 * 发表评论
 * @return
 */
function publish(){
	var title=$("#title").val();
	if(title.length<0){
		alert("标题不能为空");
	}
	var text = $("#publish_text").val();
	
	if(text.length>0){
		//发表前先检查用户是否登录
		ajaxFormSubmit("#forum_content","#forum_discuss_form");
	}else{
		alert("请填写内容");
	}
}

/**
 * 用户登录
 * @return
 */
function userLogin(){
	ajaxFormSubmit("#edit_content_div","#user_login_form");
}
/**
 * 收藏书籍的时候检查登录
 * @return
 */
//邮箱正则表达式
var reg_email = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
function stowLogin(){
	if(!reg_email.test($("#stow_email").val())){
		$("#user_email").css("color","red");
		return false;
	}else if($.trim($("#stow_passWord").val()).length<1){
		$("#user_Password").css("color","red");
		return false;
	}
	ajaxFormSubmit("#pop_login","#stow_login_form");
}
function go(){
$('#publish_text').xheditor({tools:'Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Removeformat,Align,List,Link,Unlink,Emot'});
$("#_forum_book_id").val($("#_book_id").val());
}
/**
 * 顶一下
 * @return
 */
var flagTip=true;
function tip(bookid){
	if(flagTip){
		if(bookid.length>0){
			$.ajax({
				   type: "POST",
				   url: "/forward/view/book_tip.go",
				   data: "bookid="+bookid,
				   success: function(html){
					flagTip=false;
					alert("恭喜您！操作成功，该书籍将会排名向前一小步");
				   }
				});
		}
	}else{
		alert("你只能顶一次");
	}
	
}
/**
 * 收藏
 * @return
 */
function stow(bookid,e){
	if(bookid.length>0){
		$.ajax({
			   type: "POST",
			   url: "/forward/view/favorite_stowBook.go",
			   data: "favoriteItem.type=100&favoriteItem.id="+bookid,
			   success: function(html){
					$.growlUI(html,e); 
			   }
			});
	}
}